﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Threading;
using System.IO;

namespace S7.Windows.Music
{
    /// <summary>
    /// Interaction logic for AddGenre.xaml
    /// </summary>
    public partial class AddGenre : Window
    {
        public AddGenre()
        {
            InitializeComponent();
        }

        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            string name = tbName.Text;
            if (!name.Equals(""))
            {
                Genre genre = new Genre();
                genre.GenreName = name;
                Thread thr = new Thread(new ThreadStart(() =>
                {
                    try
                    {
                        genre.Add();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Error!", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
                    }
                }));
                thr.IsBackground = true;
                thr.Start();
                Thread thrDir = new Thread(new ThreadStart(() =>
                {
                    try
                    {
                        if (!Directory.Exists(Properties.Settings.Default.MediaPath + "\\" + name))
                        {
                            Directory.CreateDirectory(Properties.Settings.Default.MediaPath + "\\" + name);
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Error!", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
                    }
                }));
                thrDir.IsBackground = true;
                thrDir.Start();
            }
            else
            {
                MessageBox.Show("Please Enter a genre name", "Error!", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
            }
        }

        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            Close();
        }
    }
}
